<template>
  <div class="common-table">
    <el-table v-loading="pageConfig.loading" :data="tableData"  height="95%" stripe border show-summary>
      <el-table-column
          show-overflow-tooltip
          v-for="attr in tableAttr"
          :key="attr.field"
          :prop="attr.field"
          :label="attr.label"
          :width="attr.width ? attr.width : ''"
      >
      </el-table-column>

      <!-- 操作列     -->
      <el-table-column  fixed="right" label="操作" width="120">
        <template slot-scope="scope">
          <el-button @click="handleEdit(scope.row)" type="text" size="small">编辑</el-button>
          <el-button @click="handleDelete(scope.row)" size="mini" type="danger" >删除</el-button>
        </template>
      </el-table-column>

    </el-table>
    <el-pagination  class="pager"
                    layout="total, sizes, prev, pager, next"
                    :total="pageConfig.total"
                    :current-page.sync="pageConfig.currentPage"
                    :page-sizes="pageConfig.pageSizes"
                    :page-size="pageConfig.pageSize"
                    :disabled="pageConfig.loading"
                    @current-change="changePage"
                    @size-change="sizeChange"
    >
    </el-pagination>
  </div>
</template>

<script>
export default {
  name: "CommonTable",
  props: {
    tableAttr: Array,
    tableData: Array,
    pageConfig: Object
  },
  data() {
    return{}
  },
  methods: {
    handleEdit(row) {
      // 调用父组件的edit方法，把row传过去
      this.$emit('edit', row)
    },
    handleDelete(row) {
      this.$emit('del', row)
    },
    changePage(page) {
      this.$emit('changePage', page)
    },
    sizeChange(size) {
      this.$emit('sizeChange', size)
    }
  }
}
</script>

<style lang="less" scoped>
  body {
    margin: 0;
  }
  .common-table {
    height: calc(100% - 62px);
    position: relative;
    .pager {
      position: absolute;
      right: 20px;
    }
  }
</style>